<template>
  <div class="wrapContainer">
    <!-- 顶部 -->
    <van-sticky>
      <van-row class="top">
        <van-col span="2"><van-icon name="wap-home-o" @click='goHome' /></van-col>
        <van-col span="12" offset="4"><span>值得买</span></van-col>
        <van-col span="6">
          <van-icon name="search" @click="goSearch" />
          <i class="w20"></i>
          <van-icon name="shopping-cart-o" @click="goCart" />
        </van-col>
      </van-row>
    </van-sticky>
    <!-- 轮播图 -->
    <div class="scrollWrap">
      <div class="scrollBg">
        <van-image
          class="smallImg"
          src="http://yanxuan.nosdn.127.net/0b7676e645253f84be662aacfc051922.png"
        />
        <div class="text">严选好物 用心生活</div>
        <van-image
          src="http://yanxuan.nosdn.127.net/a93a392fb8006ba26dea38477979b7b4.jpg"
        />
      </div>
      <div class="scrollContainer">
        <div class="swiper-container">
          <div class="swiper-wrapper">
            <div class="swiper-slide">
              <div
                class="swiperItem"
                v-for="(item, index) in navList1"
                :key="index"
              >
                <van-image
                  :src="item.picUrl"
                  width="60"
                  height="60"
                ></van-image>
                <div class="itemDetail">
                  <div class="detail1">{{ item.mainTitle }}</div>
                  <div class="detail2">{{ item.viceTitle }}</div>
                </div>
              </div>
            </div>
            <div class="swiper-slide">
              <div
                class="swiperItem"
                v-for="(item, index) in navList2"
                :key="index"
              >
                <van-image
                  :src="item.picUrl"
                  width="60"
                  height="60"
                ></van-image>
                <div class="itemDetail">
                  <div class="detail1">{{ item.mainTitle }}</div>
                  <div class="detail2">{{ item.viceTitle }}</div>
                </div>
              </div>
            </div>
            <div class="swiper-slide">
              <div
                class="swiperItem"
                v-for="(item, index) in navList3"
                :key="index"
              >
                <van-image
                  :src="item.picUrl"
                  width="60"
                  height="60"
                ></van-image>
                <div class="itemDetail">
                  <div class="detail1">{{ item.mainTitle }}</div>
                  <div class="detail2">{{ item.viceTitle }}</div>
                </div>
              </div>
            </div>
            <div class="swiper-slide">
              <div
                class="swiperItem"
                v-for="(item, index) in navList4"
                :key="index"
              >
                <van-image
                  :src="item.picUrl"
                  width="60"
                  height="60"
                ></van-image>
                <div class="itemDetail">
                  <div class="detail1">{{ item.mainTitle }}</div>
                  <div class="detail2">{{ item.viceTitle }}</div>
                </div>
              </div>
            </div>
            <div class="swiper-slide">
              <div
                class="swiperItem"
                v-for="(item, index) in navList5"
                :key="index"
              >
                <van-image
                  :src="item.picUrl"
                  width="60"
                  height="60"
                ></van-image>
                <div class="itemDetail">
                  <div class="detail1">{{ item.mainTitle }}</div>
                  <div class="detail2">{{ item.viceTitle }}</div>
                </div>
              </div>
            </div>
            <div class="swiper-slide">
              <div
                class="swiperItem"
                v-for="(item, index) in navList6"
                :key="index"
              >
                <van-image
                  :src="item.picUrl"
                  width="60"
                  height="60"
                ></van-image>
                <div class="itemDetail">
                  <div class="detail1">{{ item.mainTitle }}</div>
                  <div class="detail2">{{ item.viceTitle }}</div>
                </div>
              </div>
            </div>
            <div class="swiper-slide">
              <div
                class="swiperItem"
                v-for="(item, index) in navList7"
                :key="index"
              >
                <van-image
                  :src="item.picUrl"
                  width="60"
                  height="60"
                ></van-image>
                <div class="itemDetail">
                  <div class="detail1">{{ item.mainTitle }}</div>
                  <div class="detail2">{{ item.viceTitle }}</div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="pagination">
          <span class="active"></span>
        </div>
      </div>
    </div>
    <!-- 展示内容 -->
    <van-list
      @load="onLoad"
      finished-text="没有更多了"
      v-model="loading"
      ref="vanList"
    >
      <div class="showContainer van-clearfix">
        <div class="showItem" v-for="(item, index) in showList" :key="index">
          <img
            style="vertical-align: middle; border-radius: 10px 10px 0 0"
            width="168"
            :src="item.look.lookPics[0].picUrl"
          />
          <div class="bottomShow">
            <div class="text">{{ item.look.title }}</div>
            <div class="h20"></div>
            <div class="showAuthor">
              <div class="leftdesc">
                <van-image
                  round
                  :src="item.look.avatar"
                  width="24"
                  height="24"
                ></van-image>
                <div class="userName">{{ item.look.nickname }}</div>
              </div>
              <div class="rightdesc">
                <van-image
                  src="https://yanxuan.nosdn.127.net/5097bc5f2e1eb15f2a32b56895db073a.png"
                  width="16"
                  height="16"
                ></van-image>
                <div class="seeCount">{{ item.look.readCount }}k</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import { mapActions, mapState, mapGetters } from "vuex";
import Swiper from "swiper";
import "swiper/css/swiper.min.css";
export default {
  name: "BeWorthBuying",
  data() {
    return {
      current: 0,
      loading: false,
      page: 2,
    };
  },
  mounted() {
    this.getSwiperData();
  },
  computed: {
    ...mapState({
      navList: (state) => state.beWorthBuying.navList,
      showList: (state) => state.beWorthBuying.showList,
    }),
    ...mapGetters([
      "navList1",
      "navList2",
      "navList3",
      "navList4",
      "navList5",
      "navList6",
      "navList7",
    ]),
  },
  watch: {
    navList() {
      var mySwiper = new Swiper(document.querySelector(".swiper-container"), {
        slidesPerView: 4,
        pagination: {
          el: ".swiper-pagination",
        },
        on: {
          slideChangeTransitionStart: function () {
            let span = document.querySelector(".active");
            if (this.activeIndex == 1) {
              span.style.marginLeft = 20 + "px";
            }
            if (this.activeIndex == 2) {
              span.style.marginLeft = 40 + "px";
            }
            if (this.activeIndex == 3) {
              span.style.marginLeft = 60 + "px";
            }
            if (this.activeIndex == 0) {
              span.style.marginLeft = 0;
            }
          },
        },
      });
    },
  },
  methods: {
    ...mapActions(["getSwiperData", "getShowData"]),
    onLoad() {
      this.page += 1;
      this.getShowData(this.page);

      // 加载状态结束
      this.loading = false;
    },
    // 路由跳转相关回调
    goHome(){
      this.$router.push('/home');
      this.$store.commit('clearShowList')
    },
    goCart(){
      this.$router.push('/cart')
      this.$store.commit('clearShowList')
    },
    goSearch(){
      this.$router.push('/search')
      this.$store.commit('clearShowList')
    }
  },
};
</script>

<style lang='less' scoped>
// 外层容器样式
.wrapContainer {
  height: 1000px;
  width: 375px;
  background-color: rgb(238, 238, 238);
  overflow: hidden;
  // 顶部样式
  .top {
    background-color: #fff;
    padding: 0 10px;
    height: 50px;
    line-height: 50px;
    text-align: center;
    font-size: 28px;
    overflow: hidden;
    span {
      font-size: 18px;
      display: block;
      margin-bottom: 10px;
    }
    .w20 {
      display: inline-block;
      width: 20px;
    }
  }
  // 轮播图样式
  .scrollWrap {
    position: relative;
    height: 350px;
    .scrollBg {
      position: absolute;
      top: 0;
      .text {
        position: absolute;
        z-index: 1;
        font-size: 15px;
        top: 45px;
        left: 80px;
        font-family: PingFangSC-Regular;
        color: #fff;
      }
      .smallImg {
        position: absolute;
        z-index: 1;
        width: 65px;
        height: 34.5px;
        top: 35px;
        left: 10px;
      }
    }
    .scrollContainer {
      width: 355px;
      height: 270px;
      background: #fff;
      border-radius: 10px;
      position: absolute;
      z-index: 1;
      top: 80px;
      left: 10px;
      overflow: hidden;
      // swiper样式重写！！！！！！！！！
      .swiper-container {
        width: 355px;
        height: 260px;
        overflow: hidden;
        .swiperItem {
          width: 80px;
          height: 100.5px;
          text-align: center;
          margin-top: 18px;
          margin-right: 8px;
          .itemDetail {
            .detail1 {
              font-size: 14px;
              font-weight: bold;
              color: #333333;
            }
            .detail2 {
              font-size: 12px;
              color: #999999;
            }
          }
        }
      }
      // 分页器
      .pagination {
        position: absolute;
        z-index: 20;
        right: 0;
        left: 0;
        margin: auto;
        bottom: 15px;
        width: 80px;
        height: 2.5px;
        text-align: center;
        background-color: rgb(236, 236, 236);
        border-radius: 1px;
        .active {
          display: block;
          position: absolute;
          top: 0;
          margin-left: 0px;
          left: 0;
          z-index: 21;
          width: 20px;
          height: 2.5px;
          background: rgb(221, 26, 33);
          opacity: 0.8;
        }
      }
      // swiper样式重写！！！！！！！！！
    }
  }
  // 瀑布流样式
  .showContainer {
    width: 100%;
    height: max-content;
    background-color: rgb(238, 238, 238);
    column-count: 2;
    column-gap: 0px;
    position: absolute;
    top: 415px;
    .showItem {
      width: 168px;
      margin-bottom: 15px;
      padding: 0 10px;
      break-inside: avoid;
      .bottomShow {
        background-color: #fff;
        padding: 10px 10px 0;
        border-radius: 0 0 10px 10px;
        .text {
          font-size: 14px;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          font-family: PingFangSC-Regular;
          text-align: left;
        }
        .showAuthor {
          margin-top: 5px;
          display: flex;
          overflow: hidden;
          justify-content: space-between;
          align-items: center;
          padding-bottom: 5px;
          .leftdesc {
            display: flex;
            overflow: hidden;
            .userName {
              font-size: 12px;
              margin-top: 4px;
              margin-left: 4px;
              color: #7f7f7f;
            }
          }
          .rightdesc {
            display: flex;
            .seeCount {
              font-size: 12px;
              margin-left: 2px;
              margin-top: 2px;
              color: #7f7f7f;
            }
          }
        }
      }
    }
  }
}

.h20 {
  height: 20px;
}
</style>